<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class C_user extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->load->model('m_user', '', TRUE);
	}
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
	public function index(){
		if($this->auth->is_logged_in() == false){
			redirect('c=c_login','refresh');
		}
		$this->load->view('main/v_user');
	}
	
	function get_group_list(){
		$result=$this->m_public_function->get_group_list();
		echo $result;
	}
	
	function get_user_list(){
		$result=$this->m_public_function->get_user_list();
		echo $result;
	}
	
	
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "CREATE":
				$this->create();
				break;
			case "UPDATE":
				$this->update();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	function create(){
		$user_name=trim(@$_POST["user_name"]);
		$user_name=htmlentities($user_name,ENT_QUOTES);
		$user_pass=trim(@$_POST["user_pass"]);
		$user_pass=htmlentities($user_pass,ENT_QUOTES);
		$user_group=trim(@$_POST["user_group"]);
		$user_group=htmlentities($user_group,ENT_QUOTES);
		$user_aktif=trim(@$_POST["user_aktif"]);
		$user_aktif=htmlentities($user_aktif,ENT_QUOTES);
		
		$result=$this->m_user->create($user_name, $user_pass, $user_group, $user_aktif);
		echo $result;
	}
	
	function update(){
		$user_id=@$_POST["user_id"];
		$user_id=is_numeric($user_id)?$user_id:0;
		$user_name=trim(@$_POST["user_name"]);
		$user_name=htmlentities($user_name,ENT_QUOTES);
		$user_pass=trim(@$_POST["user_pass"]);
		$user_pass=htmlentities($user_pass,ENT_QUOTES);
		$user_group=trim(@$_POST["user_group"]);
		$user_group=htmlentities($user_group,ENT_QUOTES);
		$user_aktif=trim(@$_POST["user_aktif"]);
		$user_aktif=htmlentities($user_aktif,ENT_QUOTES);
		
		$result=$this->m_user->update($user_id, $user_name, $user_pass, $user_group, $user_aktif);
		echo $result;
	}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */